package database;

import Other.Glob;
import enums.SearchType;

public class MySupplier extends NewTirDataBase {
	
	private String supplierID;
	private String name;
	private String address;
	private String postcode;
	private String town;
	private String province;
	private String maturity;
	private String countryCodeID;
	private String countryName;
	private String phoneNumber;
	private String fax;
	private String nif;
	private String paymentCodeID;
	private String paymentName;
	private String taxCodeID;
	private String taxName;
	private String email;
	
	private static final int SUPPLIER_ID = 0;
	private static final int NAME = 1;
	private static final int ADDRESS = 2;
	private static final int POSTCODE = 3;
	private static final int TOWN = 4;
	private static final int PROVINCE = 5; 
	private static final int MATURITY = 6; 
	private static final int CODE_COUNTRY_ID = 7;
	private static final int PHONE_NUMBER = 8;
	private static final int FAX = 9;
	private static final int NIF = 10;
	private static final int PAYMENT_CODE_ID = 11;
	private static final int TAX_CODE_ID = 12;
	private static final int EMAIL = 13;
	
	
public MySupplier() {
		
	}
	
	public MySupplier (String[] data) {
		
		super();
		this.supplierID = data[SUPPLIER_ID];
		this.name = data[NAME];
		this.address = data[ADDRESS];
		this.postcode = data[POSTCODE];
		this.town = data[TOWN];
		this.province = data[PROVINCE];
		this.maturity = data[MATURITY];
		this.countryCodeID = data[CODE_COUNTRY_ID];
		System.out.println("This is the countryID inside the constructor after it has been set up" + countryCodeID);
		this.phoneNumber = data[PHONE_NUMBER];
		this.fax = data[FAX];
		this.nif = data[NIF];
		this.paymentCodeID = data[PAYMENT_CODE_ID];
		this.taxCodeID = data[TAX_CODE_ID];
		this.email = data[EMAIL];
		
		
		countryName ="";
		
		Glob.type = SearchType.COUNTRY;
		
		//System.out.println("Search type before looking for the country " + Glob.type);
		for (NewTirDataBase c : DatabaseExtension.getTableID("Select * from country")) {
			if (((MyCountry) c).getCountryID().trim().replaceAll("\n", "").equals(countryCodeID)) {
				//System.out.println("This is the country ID inside MyAddressee constructor " + ((MyCountry) c).getCountryID().trim().replaceAll("\n", ""));
				countryName = String.format("%s",((MyCountry) c).getCountryName());
			}
				
		}
		
		paymentName ="";
		
		Glob.type = SearchType.PAYMENT;
		
		//System.out.println("Search type before looking for the country " + Glob.type);
		for (NewTirDataBase p : DatabaseExtension.getTableID("Select * from payment")) {
			if (((MyPayment) p).getPaymentID().trim().replaceAll("\n", "").equals(paymentCodeID)) {
				//System.out.println("This is the payment ID inside MyAddressee constructor " + ((MyPayment) p).getPaymentID().trim().replaceAll("\n", ""));
				paymentName = String.format("%s",((MyPayment) p).getPaymentName());
			}
				
		}
		
		taxName ="";
		
		Glob.type = SearchType.TAX;
		
		//System.out.println("Search type before looking for the country " + Glob.type);
		for (NewTirDataBase t : DatabaseExtension.getTableID("Select * from tax")) {
			if (((MyTax) t).getTaxID().trim().replaceAll("\n", "").equals(taxCodeID)) {
				//System.out.println("This is the payment ID inside MyAddressee constructor " + ((MyTax) t).getTaxID().trim().replaceAll("\n", ""));
				taxName = String.format("%s",((MyTax) t).getTaxName());
			}
				
		}
		
		
		Glob.type = SearchType.SUPPLIER;
		//System.out.println("Search type after looking for the country " + Glob.type);
	}

	public String getSupplierID() {
		return supplierID;
	}

	public void setSupplierID(String supplierID) {
		this.supplierID = supplierID;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}
	
	
	public String getMaturity() {
		return maturity;
	}

	public void setMaturity(String maturity) {
		this.maturity = maturity;
	}

	public String getCountryCodeID() {
		return countryCodeID;
	}

	public void setCountryCodeID(String countryCodeID) {
		this.countryCodeID = countryCodeID;
	}

	public String getCountryName() {
		return countryName;
	}

	public void setCountryName(String countryName) {
		this.countryName = countryName;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getNif() {
		return nif;
	}

	public void setNif(String nif) {
		this.nif = nif;
	}

	public String getPaymentCodeID() {
		return paymentCodeID;
	}

	public void setPaymentCodeID(String paymentCodeID) {
		this.paymentCodeID = paymentCodeID;
	}

	public String getPaymentName() {
		return paymentName;
	}

	public void setPaymentName(String paymentName) {
		this.paymentName = paymentName;
	}

	public String getTaxCodeID() {
		return taxCodeID;
	}

	public void setTaxCodeID(String taxCodeID) {
		this.taxCodeID = taxCodeID;
	}

	public String getTaxName() {
		return taxName;
	}

	public void setTaxName(String taxName) {
		this.taxName = taxName;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	
	

}
